import java.awt.*;
import java.awt.event.InputEvent;

public class Test {
    public static void main(String[] args) throws InterruptedException {
        Thread.sleep(5000);
        // 检测举手
        int x2 = 1486;
        int y2 = 970;

        // save the initial color
        Robot robot = null;
        try {
            robot = new Robot();
        } catch (AWTException e) {
            throw new RuntimeException(e);
        }
        Color initialColor2 = robot.getPixelColor(x2, y2);

        // wait for color change
        while (robot.getPixelColor(x2, y2).equals(Color.white)
                || robot.getPixelColor(x2-10, y2).equals(initialColor2)
                || robot.getPixelColor(x2-20, y2).equals(initialColor2)
                || robot.getPixelColor(x2+10, y2).equals(initialColor2)
                || robot.getPixelColor(x2+20, y2).equals(initialColor2)
                || robot.getPixelColor(x2+30, y2).equals(initialColor2)
        ) {
            Thread.sleep(50);
        }
        Thread.sleep(800);
        // click the mouse
        // 没加这个循环之前测试结果一直都不对, 后面加了循环循环了10次鼠标才能正确移动到这个位置
        for (int i = 0; i < 10; i++) {
            robot.mouseMove(x2, y2);
        }
        // System.out.println(MouseInfo.getPointerInfo().getLocation().getX() + " , " + MouseInfo.getPointerInfo().getLocation().getY());
        robot.mousePress(InputEvent.BUTTON1_MASK);
        // robot.delay(100);
        robot.mouseRelease(InputEvent.BUTTON1_MASK);
        System.out.println("成功");
    }
    public static void main1(String[] args) throws AWTException, InterruptedException {
        Robot rb = new Robot();
        System.out.println("start");
        Thread.sleep(500);
        for (int i = 0; i < 5; i++) {
            rb.mouseMove(1486, 970);
            // rb.mouseMove(37, 99);

        }
        System.out.println(MouseInfo.getPointerInfo().getLocation().getX() + " , " + MouseInfo.getPointerInfo().getLocation().getY());
        rb.mousePress(InputEvent.BUTTON1_MASK);

        // rb.delay(50);
        rb.mouseRelease(InputEvent.BUTTON1_MASK);
    }
}
